package org.cloudlab.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.cloudlab.bean.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * 重写登录用户对象的实现类
 *
 * @author Liu Yicong
 * @date 2023/9/5
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginUser implements UserDetails {

	public LoginUser(SysUser user) {
		this.userId = user.getId();
		this.userName = user.getUserName();
		this.nickName = user.getNickName();
		this.password = user.getPassword();
		this.role = user.getRole();
	}

	private Long userId;

	private String userName;

	private String nickName;

	private String password;

	private String role;

	/**
	 * 获取用户权限
	 *
	 * @return TODO TOTAL
	 * 1. 修改频繁更新用户最后登录时间的问题 SELECT id,user_name,nick_name,password,role,create_time,last_login_time FROM sys_user WHERE (user_name = ?)
	 * UPDATE sys_user SET user_name=?, nick_name=?, password=?, role=?, create_time=?, last_login_time=? WHERE id=?
	 */
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return null;
	}


	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public String getUsername() {
		return userName;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}
}
